package com.ruoyi.web.controller.statistics;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.UnitUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.statistics.domain.StatisticsTrain;
import com.ruoyi.statistics.service.IStatisticsTrainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;

/**
 * 技术培训 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-11-11
 */
@Controller
@RequestMapping("/statistics/statisticsTrain")
public class StatisticsTrainController extends BaseController
{
    private String prefix = "statistics/statisticsTrain";
	
	@Autowired
	private IStatisticsTrainService statisticsTrainService;
	
	@RequiresPermissions("statistics:statisticsTrain:view")
	@GetMapping()
	public String statisticsTrain(ModelMap mmap)
	{

		int realcount=0;
		int teachercount=0;

		int daqing_count = 0;int daqing_xueyuan = 0;int daqing_teacher = 0;int liaohe_count = 0;int liaohe_xueyuan = 0;int liaohe_teacher = 0;
		int changqing_count = 0;int changqing_xueyuan = 0;int changqing_teacher = 0;int talimu_count = 0;int talimu_xueyuan = 0;int talimu_teacher = 0;
		int xinjiang_count = 0;int xinjiang_xueyuan = 0;int xinjiang_teacher = 0;int xinan_count = 0;int xinan_xueyuan = 0;int xinan_teacher = 0;
		int jilin_count = 0;int jilin_xueyuan = 0;int jilin_teacher = 0;int dagang_count = 0;int dagang_xueyuan = 0;int dagang_teacher = 0;
		int qinghai_count = 0;int qinghai_xueyuan = 0;int qinghai_teacher = 0;int huabei_count = 0;int huabei_xueyuan = 0;int huabei_teacher = 0;
		int tuha_count = 0;int tuha_xueyuan = 0;int tuha_teacher = 0;int jidong_count = 0;int jidong_xueyuan = 0;int jidong_teacher = 0;
		int yumen_count = 0;int yumen_xueyuan = 0;int yumen_teacher = 0;int meicengqi_count = 0;int meicengqi_xueyuan = 0;int meicengqi_teacher = 0;
		int nanfang_count = 0;int nanfang_xueyuan = 0;int nanfang_teacher = 0;int kantanbeijing_count = 0;int kantanbeijing_xueyuan = 0;int kantanbeijing_teacher = 0;
		int zhejiang_count = 0;int zhejiang_xueyuan = 0;int zhejiang_teacher = 0;int kantanxibei_count = 0;int kantanxibei_xueyuan = 0;int kantanxibei_teacher = 0;
		int hanzhoudizhi_count = 0;int hanzhoudizhi_xueyuan = 0;int hanzhoudizhi_teacher = 0;

		List<StatisticsTrain> list = statisticsTrainService.selectStatisticsTrainList(new StatisticsTrain());
		mmap.put("traincount", list.size());

		for (int i = 0; i < list.size(); i++) {
			StatisticsTrain statisticsTrain =list.get(i);

			String realcount1 =statisticsTrain.getRealcount();
			if (StringUtils.isNotEmpty(realcount1)){
				realcount+=Integer.parseInt(realcount1);
			}

			String teachercount1 =statisticsTrain.getTeachercount();
			if (StringUtils.isNotEmpty(teachercount1)){
				teachercount+=Integer.parseInt(teachercount1);
			}

			if (statisticsTrain.getUnitid().equals("1"))
			{
				daqing_count++;
				daqing_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				daqing_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("2"))
			{
				liaohe_count++;
				liaohe_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				liaohe_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("3"))
			{
				changqing_count++;
				changqing_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				changqing_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("4"))
			{
				talimu_count++;
				talimu_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				talimu_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("5"))
			{
				xinjiang_count++;
				xinjiang_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				xinjiang_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("6"))
			{
				xinan_count++;
				xinan_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				xinan_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("7"))
			{
				jilin_count++;
				jilin_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				jilin_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("8"))
			{
				dagang_count++;
				dagang_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				dagang_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("9"))
			{
				qinghai_count++;
				qinghai_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				qinghai_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("10"))
			{
				huabei_count++;
				huabei_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				huabei_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("11"))
			{
				tuha_count++;
				tuha_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				tuha_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("12"))
			{
				jidong_count++;
				jidong_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				jidong_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("13"))
			{
				yumen_count++;
				yumen_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				yumen_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("14"))
			{
				zhejiang_count++;
				zhejiang_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				zhejiang_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("15"))
			{
				meicengqi_count++;
				meicengqi_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				meicengqi_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("16"))
			{
				nanfang_count++;
				nanfang_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				nanfang_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("17"))
			{
				kantanbeijing_count++;
				kantanbeijing_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				kantanbeijing_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("18"))
			{
				kantanxibei_count++;
				kantanxibei_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				kantanxibei_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
			else if (statisticsTrain.getUnitid().equals("19"))
			{
				hanzhoudizhi_count++;
				hanzhoudizhi_xueyuan += Integer.parseInt(statisticsTrain.getRealcount());
				hanzhoudizhi_teacher += Integer.parseInt(statisticsTrain.getDaycount());
			}
		}
		mmap.put("realcount", realcount);
		mmap.put("teachercount", teachercount);

		mmap.put("traincounts", daqing_count + "," + liaohe_count + "," + changqing_count + "," + talimu_count + "," + xinjiang_count + "," + xinan_count + "," +
				jilin_count + "," + dagang_count + "," + qinghai_count + "," + huabei_count + "," + tuha_count + "," + jidong_count + "," + yumen_count + "," +
				zhejiang_count + "," + meicengqi_count + "," + nanfang_count + "," + kantanbeijing_count + "," + kantanxibei_count + "," + hanzhoudizhi_count);
		mmap.put("trainpeoples", daqing_xueyuan + "," + liaohe_xueyuan + "," + changqing_xueyuan + "," + talimu_xueyuan + "," + xinjiang_xueyuan + "," + xinan_xueyuan + "," +
				jilin_xueyuan + "," + dagang_xueyuan + "," + qinghai_xueyuan + "," + huabei_xueyuan + "," + tuha_xueyuan + "," + jidong_xueyuan + "," + yumen_xueyuan + "," +
				zhejiang_xueyuan + "," + meicengqi_xueyuan + "," + nanfang_xueyuan + "," + kantanbeijing_xueyuan + "," + kantanxibei_xueyuan + "," + hanzhoudizhi_xueyuan);
		mmap.put("trainteachers", daqing_teacher + "," + liaohe_teacher + "," + changqing_teacher + "," + talimu_teacher + "," + xinjiang_teacher + "," + xinan_teacher + "," +
				jilin_teacher + "," + dagang_teacher + "," + qinghai_teacher + "," + huabei_teacher + "," + tuha_teacher + "," + jidong_teacher + "," + yumen_teacher + "," +
				zhejiang_teacher + "," + meicengqi_teacher + "," + nanfang_teacher + "," + kantanbeijing_teacher + "," + kantanxibei_teacher + "," + hanzhoudizhi_teacher);

		return prefix + "/statisticsTrain";
	}
	
	/**
	 * 查询技术培训列表
	 */
	@RequiresPermissions("statistics:statisticsTrain:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(StatisticsTrain statisticsTrain)
	{
		startPage();
        List<StatisticsTrain> list = statisticsTrainService.selectStatisticsTrainList(statisticsTrain);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出技术培训列表
	 */
	@RequiresPermissions("statistics:statisticsTrain:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatisticsTrain statisticsTrain)
    {
    	List<StatisticsTrain> list = statisticsTrainService.selectStatisticsTrainList(statisticsTrain);
        ExcelUtil<StatisticsTrain> util = new ExcelUtil<StatisticsTrain>(StatisticsTrain.class);
        return util.exportExcel(list, "statisticsTrain");
    }

	@PostMapping("/importData")
	@ResponseBody
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
	{
		ExcelUtil<StatisticsTrain> util = new ExcelUtil<StatisticsTrain>(StatisticsTrain.class);
		List<StatisticsTrain> trainList = util.importExcel(file.getInputStream());
		for (StatisticsTrain statisticsTrain:trainList) {
			statisticsTrain.setUnitid(UnitUtils.getUnitId(statisticsTrain.getUnit()));
			statisticsTrainService.insertStatisticsTrain(statisticsTrain);
		}
		return AjaxResult.success("导入成功");
	}

	/**
	 * 新增技术培训
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存技术培训
	 */
	@RequiresPermissions("statistics:statisticsTrain:add")
	@Log(title = "技术培训", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(StatisticsTrain statisticsTrain)
	{
		statisticsTrain.setUnit(UnitUtils.unitById(statisticsTrain.getUnitid()));
		return toAjax(statisticsTrainService.insertStatisticsTrain(statisticsTrain));
	}

	/**
	 * 修改技术培训
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		StatisticsTrain statisticsTrain = statisticsTrainService.selectStatisticsTrainById(id);
		mmap.put("statisticsTrain", statisticsTrain);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存技术培训
	 */
	@RequiresPermissions("statistics:statisticsTrain:edit")
	@Log(title = "技术培训", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(StatisticsTrain statisticsTrain)
	{
		statisticsTrain.setUnit(UnitUtils.unitById(statisticsTrain.getUnitid()));
		return toAjax(statisticsTrainService.updateStatisticsTrain(statisticsTrain));
	}
	
	/**
	 * 删除技术培训
	 */
	@RequiresPermissions("statistics:statisticsTrain:remove")
	@Log(title = "技术培训", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(statisticsTrainService.deleteStatisticsTrainByIds(ids));
	}
	
}
